package com.hongshan.wallet.core.home

import android.app.Application
import android.databinding.ObservableField
import android.view.View
import com.hongshan.wallet.Constant
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.TradingAlertBean
import com.hongshan.wallet.format
import com.hongshan.wallet.router.RouterIndex
import com.hongshan.wallet.router.go

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.home
 * @author   : zhangxx
 * @data     : 2019/3/21
 * @email    : qq957413212@hotmail.com
 */
class HomeTradingRecyclerViewModel(application: Application) : MyViewModel(application) {

    val collectionType = ObservableField<String>("支付宝收款")
    val collectionAccount = ObservableField<String>("17*********")
    val collectionMoney = ObservableField<String>("20000.00")
    val collectionTime = ObservableField<String>("2018-08-08 08:00")
//    val icon = ObservableField<Int>(R.drawable.ic_icbc)
    var alertBean:TradingAlertBean? = null

    fun setItemInfo(tradingAlertBean: TradingAlertBean) {
        collectionType.set(when(tradingAlertBean.pay_type){
            1 -> "支付宝收款"
            2 -> "微信收款"
            else -> null
        })
        collectionMoney.set(tradingAlertBean.price?.toString())
        collectionAccount.set(tradingAlertBean.account)
        collectionTime.set(tradingAlertBean.create_time.format("yyyy-MM-dd HH:mm"))
//        icon.set(when(tradingAlertBean.pay_type){
//            1 -> R.drawable.ic_zfb
//            2 -> R.drawable.ic_icbc
//            else -> null
//        })
        alertBean = tradingAlertBean
    }

    val details = View.OnClickListener {
        go(RouterIndex.ORDER_DESC, mapOf(Constant.ROUTE_PARAMS_KEY.ORDER_ID to alertBean?.order_id?.toInt()))
    }

}